package com.yuxl.ai.knowledgeText.controller;

import com.yuxl.ai.knowledgeText.entity.AiKnowledgeText;
import com.yuxl.ai.knowledgeText.entity.AiKnowledgeTextEmbedding;
import com.yuxl.ai.knowledgeText.service.AiKnowledgeTextService;
import com.yuxl.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.List;


/**
 * @Author : yuxl
 * @create 2025/7/10 下午6:09
 */
@Tag(name = "文本知识库")
@RequestMapping("/ai/knowledgeText")
@RestController
public class AiKnowledgeTextController {
    @Resource
    private AiKnowledgeTextService aiKnowledgeTextService;

    @Operation(summary = "创建文本知识库")
    @PostMapping
    public Mono<AiKnowledgeText> create(@RequestBody AiKnowledgeText entity) {
        return aiKnowledgeTextService.create(entity);
    }

    @Operation(summary = "根据ID查询文本知识库")
    @GetMapping("/{id}")
    public Mono<R<AiKnowledgeText>> getById(@Parameter(description = "文本知识库ID") @PathVariable Long id) {
        return aiKnowledgeTextService.findById(id)
                .map(R::ok);
    }

    @Operation(summary = "更新文本知识库")
    @PutMapping
    public Mono<R<AiKnowledgeText>> updateById(@RequestBody AiKnowledgeText entity) {
        return aiKnowledgeTextService.updateById(entity)
                .map(R::ok);
    }


    @Operation(summary = "删除文本知识库")
    @DeleteMapping("/{id}")
    public Mono<R<Void>> deleteById(@Parameter(description = "文本知识库ID") @PathVariable Long id) {
        return aiKnowledgeTextService.deleteById(id)
                .thenReturn(R.ok());
    }

    @Operation(summary = "条件查询文本知识库列表")
    @PostMapping("/list")
    public Mono<R<List<AiKnowledgeText>>> list(@RequestBody AiKnowledgeText entity) {
        return aiKnowledgeTextService.list(entity)
                .collectList()
                .map(R::ok);
    }

    @Operation(summary = "统计文本知识库数量")
    @PostMapping("/count")
    public Mono<R<Integer>> count(@RequestBody AiKnowledgeText entity) {
        return aiKnowledgeTextService.count(entity)
                .map(R::ok);
    }

    @Operation(summary = "分页条件查询文本知识库")
    @PostMapping("/{page}/{size}/page")
    public Mono<R<List<AiKnowledgeText>>> page(
            @RequestBody AiKnowledgeText entity,
            @PathVariable int page,
            @PathVariable int size
    ) {
        return aiKnowledgeTextService.page(entity, page, size)
                .collectList()
                .map(R::ok);
    }
}
